//MooTools More, <http://mootools.net/more>. Copyright (c) 2006-2009 Aaron Newton <http://clientcide.com/>, Valerio Proietti <http://mad4milk.net> & the MooTools team <http://mootools.net/developers>, MIT Style License.

MooTools.More={version:"1.2.2.2"};Fx.Scroll=new Class({Extends:Fx,options:{offset:{x:0,y:0},wheelStops:true},initialize:function(b,a){this.element=this.subject=$(b);
this.parent(a);var d=this.cancel.bind(this,false);if($type(this.element)!="element"){this.element=$(this.element.getDocument().body);}var c=this.element;
if(this.options.wheelStops){this.addEvent("start",function(){c.addEvent("mousewheel",d);},true);this.addEvent("complete",function(){c.removeEvent("mousewheel",d);
},true);}},set:function(){var a=Array.flatten(arguments);this.element.scrollTo(a[0],a[1]);},compute:function(c,b,a){return[0,1].map(function(d){return Fx.compute(c[d],b[d],a);
});},start:function(c,h){if(!this.check(c,h)){return this;}var e=this.element.getSize(),f=this.element.getScrollSize();var b=this.element.getScroll(),d={x:c,y:h};
for(var g in d){var a=f[g]-e[g];if($chk(d[g])){d[g]=($type(d[g])=="number")?d[g].limit(0,a):a;}else{d[g]=b[g];}d[g]+=this.options.offset[g];}return this.parent([b.x,b.y],[d.x,d.y]);
},toTop:function(){return this.start(false,0);},toLeft:function(){return this.start(0,false);},toRight:function(){return this.start("right",false);},toBottom:function(){return this.start(false,"bottom");
},toElement:function(b){var a=$(b).getPosition(this.element);return this.start(a.x,a.y);}});

(function(){var b={wait:function(c){return this.chain(function(){this.callChain.delay($pick(c,500),this);}.bind(this));
}};Chain.implement(b);if(window.Fx){Fx.implement(b);["Css","Tween","Elements"].each(function(c){if(Fx[c]){Fx[c].implement(b);}});}try{Element.implement({chains:function(c){$splat($pick(c,["tween","morph","reveal"])).each(function(d){d=this.get(d);
if(!d){return;}d.setOptions({link:"chain"});},this);return this;},pauseFx:function(d,c){this.chains(c).get($pick(c,"tween")).wait(d);return this;}});}catch(a){}})();

MooTools.More={version:"1.2.2.2"};
var Asset={javascript:function(f,d){d=$extend({onload:$empty,document:document,check:$lambda(true)},d);var b=new Element("script",{src:f,type:"text/javascript"});
var e=d.onload.bind(b),a=d.check,g=d.document;delete d.onload;delete d.check;delete d.document;b.addEvents({load:e,readystatechange:function(){if(["loaded","complete"].contains(this.readyState)){e();
}}}).set(d);if(Browser.Engine.webkit419){var c=(function(){if(!$try(a)){return;}$clear(c);e();}).periodical(50);}return b.inject(g.head);},css:function(b,a){return new Element("link",$merge({rel:"stylesheet",media:"screen",type:"text/css",href:b},a)).inject(document.head);
},image:function(c,b){b=$merge({onload:$empty,onabort:$empty,onerror:$empty},b);var d=new Image();var a=$(d)||new Element("img");["load","abort","error"].each(function(e){var f="on"+e;
var g=b[f];delete b[f];d[f]=function(){if(!d){return;}if(!a.parentNode){a.width=d.width;a.height=d.height;}d=d.onload=d.onabort=d.onerror=null;g.delay(1,a,a);
a.fireEvent(e,a,1);};});d.src=a.src=c;if(d&&d.complete){d.onload.delay(1);}return a.set(b);},images:function(d,c){c=$merge({onComplete:$empty,onProgress:$empty,onError:$empty},c);
d=$splat(d);var a=[];var b=0;return new Elements(d.map(function(e){return Asset.image(e,{onload:function(){c.onProgress.call(this,b,d.indexOf(e));b++;if(b==d.length){c.onComplete();
}},onerror:function(){c.onError.call(this,b,d.indexOf(e));b++;if(b==d.length){c.onComplete();}}});}));}};
Fx.Elements=new Class({Extends:Fx.CSS,initialize:function(b,a){this.elements=this.subject=$$(b);this.parent(a);},compute:function(g,h,j){var c={};
for(var d in g){var a=g[d],e=h[d],f=c[d]={};for(var b in a){f[b]=this.parent(a[b],e[b],j);}}return c;},set:function(b){for(var c in b){var a=b[c];for(var d in a){this.render(this.elements[c],d,a[d],this.options.unit);
}}return this;},start:function(c){if(!this.check(c)){return this;}var h={},j={};for(var d in c){var f=c[d],a=h[d]={},g=j[d]={};for(var b in f){var e=this.prepare(this.elements[d],b,f[b]);
a[b]=e.from;g[b]=e.to;}}return this.parent(h,j);}});

Array.implement({min:function(){return Math.min.apply(null,this);},max:function(){return Math.max.apply(null,this);},average:function(){return this.length?this.sum()/this.length:0;
},sum:function(){var a=0,b=this.length;if(b){do{a+=this[--b];}while(b);}return a;},unique:function(){return[].combine(this);}});

var Tips = new Class({

   Implements: [Events, Options],

   options: {
      onShow: function(tip){
         tip.setStyle('visibility', 'visible');
      },
      onHide: function(tip){
         tip.setStyle('visibility', 'hidden');
      },
      showDelay: 100,
      hideDelay: 100,
      className: 'tool',
      offsets: {x: 16, y: 16},
      fixed: false
   },

   initialize: function(){
      var params = Array.link(arguments, {options: Object.type, elements: $defined});
      this.setOptions(params.options || null);
      this.tip = new Element('div',{'class': this.options.className + '-tip'}).inject(document.body);
      if (this.options.className) this.tip.addClass(this.options.className);
      var top = new Element('div', {'class': 'tip-top'}).inject(this.tip);
      this.container = new Element('div', {'class': 'tip'}).inject(this.tip);
      var bottom = new Element('div', {'class': 'tip-bottom'}).inject(this.tip);
      this.tip.setStyles({position: 'absolute', top: 0, left: 0, visibility: 'hidden'});
      if (params.elements) this.attach(params.elements);
   },
   
   attach: function(elements){
      $$(elements).each(function(element){
         var title = element.retrieve('tip:title', element.get('title'));
         var dual = title   .split('::');
         var text = element.retrieve('tip:text', element.get('rel') || element.get('href'));
         if (dual.length > 1){
            var text = dual[1].trim();
            var title = dual[0].trim();
         }else{
            var text = dual[0].trim();
            var title = '';
         }
         element.store('tip:title', title);
         element.store('tip:text', text);
         var enter = element.retrieve('tip:enter', this.elementEnter.bindWithEvent(this, element));
         var leave = element.retrieve('tip:leave', this.elementLeave.bindWithEvent(this, element));
         element.addEvents({mouseenter: enter, mouseleave: leave});
         if (!this.options.fixed){
            var move = element.retrieve('tip:move', this.elementMove.bindWithEvent(this, element));
            element.addEvent('mousemove', move);
         }
         element.store('tip:native', element.get('title'));
         element.erase('title');
      }, this);
      return this;
   },
   
   detach: function(elements){
      $$(elements).each(function(element){
         element.removeEvent('mouseenter', element.retrieve('tip:enter') || $empty);
         element.removeEvent('mouseleave', element.retrieve('tip:leave') || $empty);
         element.removeEvent('mousemove', element.retrieve('tip:move') || $empty);
         element.eliminate('tip:enter').eliminate('tip:leave').eliminate('tip:move');
         var original = element.retrieve('tip:native');
         if (original) element.set('title', original);
      });
      return this;
   },
   
   elementEnter: function(event, element){
      $A(this.container.childNodes).each(Element.dispose);
      var title = element.retrieve('tip:title');
      if (title){
         this.titleElement = new Element('div', {'class': this.options.className + '-title'}).inject(this.container);
         this.fill(this.titleElement, title);
      }
      
      var text = element.retrieve('tip:text');
      if (text){
         this.textElement = new Element('div', {'class': this.options.className + '-text'}).inject(this.container);
         this.fill(this.textElement, text);
      }
      this.timer = $clear(this.timer);
      this.timer = this.show.delay(this.options.showDelay, this);

      this.position((!this.options.fixed) ? event : {page: element.getPosition()});
   },
   
   elementLeave: function(event){
      $clear(this.timer);
      this.timer = this.hide.delay(this.options.hideDelay, this);
   },
   
   elementMove: function(event){
      this.position(event);
   },
   
   position: function(event){
      var size = window.getSize(), scroll = window.getScroll();
      var tip = {x: this.tip.offsetWidth, y: this.tip.offsetHeight};
      var props = {x: 'left', y: 'top'};
      for (var z in props){
         var pos = event.page[z] + this.options.offsets[z];
         if ((pos + tip[z] - scroll[z]) > size[z]) pos = event.page[z] - this.options.offsets[z] - tip[z];
         this.tip.setStyle(props[z], pos);
      }
   },
   
   fill: function(element, contents){
      (typeof contents == 'string') ? element.set('html', contents) : element.adopt(contents);
   },

   show: function(){
      this.fireEvent('show', this.tip);
   },

   hide: function(){
      this.fireEvent('hide', this.tip);
   }

});



